<template>
<div style="width: 100%">
  <a-card class="card" :bordered="false">
    <div class="table-page-search-wrapper">
      <a-form layout="vertical">
        <a-row :gutter="48">
          <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}">
            <a-form-item label="准考证号">
              <a-input placeholder="请输入..." v-model="queryParam.zkzh"/>
            </a-form-item>
          </a-col>
          <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}" >
            <a-form-item label="院系">
              <a-select :allowClear="true" showSearch optionFilterProp="children" v-model="queryParam.ssyxm" @change="yxChange">
                <a-select-option v-for="i in selectMenu.yx" :key="i.id" :value="i.dwh">{{ i.dwmc }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <template v-if="advanced">
          <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}">
            <a-form-item label="专业">
              <a-select :allowClear="true" showSearch optionFilterProp="children" v-model="queryParam.zy">
                <a-select-option v-for="i in TYPE0126" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}">
            <a-form-item label="研究方向">
              <a-select :allowClear="true" showSearch optionFilterProp="children" v-model="queryParam.zy">
                <a-select-option v-for="i in TYPE0126" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}">
            <a-form-item label="姓名">
              <a-input placeholder="请输入..." v-model="queryParam.ksxm"/>
            </a-form-item>
          </a-col>
          <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}">
            <a-form-item label="科目一">
               <a-row :gutter="0" style="overflow:hidden">
                <a-col span="12">
                  <a-select showSearch optionFilterProp="children" :allowClear="true"  v-model="queryParam.sznj">
                    <a-select-option v-for="i in TYPE0126" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
                  </a-select>
                </a-col>
                <a-col span="12">
                  <a-input placeholder="请输入..." v-model="queryParam.ksxm"/>
                </a-col>
              </a-row>
            </a-form-item>
          </a-col>
          <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}">
            <a-form-item label="科目二">
              <a-row :gutter="0" style="overflow:hidden">
                <a-col span="12">
                  <a-select :allowClear="true" showSearch optionFilterProp="children" v-model="queryParam.sznj">
                    <a-select-option v-for="i in TYPE0126" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
                  </a-select>
                </a-col>
                <a-col span="12">
                  <a-input placeholder="请输入..." v-model="queryParam.ksxm"/>
                </a-col>
              </a-row>
            </a-form-item>
          </a-col>
          <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}">
            <a-form-item label="科目三">
              <a-row :gutter="0" style="overflow:hidden">
                <a-col span="12">
                  <a-select :allowClear="true" showSearch optionFilterProp="children" v-model="queryParam.sznj">
                    <a-select-option v-for="i in TYPE0126" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
                  </a-select>
                </a-col>
                <a-col span="12">
                  <a-input placeholder="请输入..." v-model="queryParam.ksxm"/>
                </a-col>
              </a-row>
            </a-form-item>
          </a-col>
          <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}">
            <a-form-item label="科目四">
              <a-row :gutter="0" style="overflow:hidden">
                <a-col span="12">
                  <a-select :allowClear="true" showSearch optionFilterProp="children" v-model="queryParam.sznj">
                    <a-select-option v-for="i in TYPE0126" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
                  </a-select>
                </a-col>
                <a-col span="12">
                  <a-input placeholder="请输入..." v-model="queryParam.ksxm"/>
                </a-col>
              </a-row>
            </a-form-item>
          </a-col>
          <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}">
            <a-form-item label="总成绩">
              <a-row :gutter="0" style="overflow:hidden">
                <a-col span="12">
                  <a-select :allowClear="true" showSearch optionFilterProp="children" v-model="queryParam.sznj">
                    <a-select-option v-for="i in TYPE0126" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
                  </a-select>
                </a-col>
                <a-col span="12">
                  <a-input placeholder="请输入..." v-model="queryParam.ksxm"/>
                </a-col>
              </a-row>
            </a-form-item>
          </a-col>
          </template>
          <a-col :sm="{span:20}" :xl="{span:10}">
            <a-button type="primary" @click="loadData">查询</a-button>
            <a-button type="primary" @click="handleExport">导出</a-button>
            <a-button type="primary" @click="handleBatchApply">批量申请</a-button>
            <a @click="advanced = !advanced" style="margin-left: 8px">
                {{ advanced ? '收起' : '展开' }}
                <a-icon :type="advanced ? 'up' : 'down'"/>
              </a>
          </a-col>
        </a-row>
      </a-form>
    </div>
    </a-card>
    <a-card class="card" :bordered="false">
    <a-table
      ref="table"
      size="default"
      rowKey="key"
      :columns="columns"
      :loading="loading"
      :dataSource="data"
      :alert="options.alert"
      :rowSelection="options.rowSelection"
      :pagination="false"
      :scroll="{ x: 1500 }"
    >
      <span slot="serial" slot-scope="text, record, index">
        {{ index + 1 }}
      </span>
    </a-table>
  <!-- 审查 -->
  <bonus-apply @close="handleApplyClose" @success="handleApplySuccess" :bonusApplyVisible="bonusApplyVisible" ></bonus-apply>
    </a-card>
</div>
</template>

<script>
import BonusApply from './bonusApply'
// import moment from 'moment'
import { STable } from '~'
import { mapState } from 'vuex'

const selectArr = ['TYPE0126', 'TYPE0075', 'TYPE0125', 'TYPE0072']

export default {
  components: {
    STable,
    BonusApply
  },
  data () {
    return {
      advanced: true,
      bonusApplyVisible: false,
      loading: false,
      data: [],
      // 查询参数
      queryParam: {
        hzfs: 'yx'
      },
      postParams: {},
      // 表头
      columns: [
        {
          title: '序号',
          scopedSlots: { customRender: 'serial' }
        },
        {
          title: '考生编号',
          dataIndex: 'xmbh'
        },
        {
          title: '姓名',
          dataIndex: 'xm'
        },
        {
          title: '报考院系',
          dataIndex: 'bkyx'
        },
        {
          title: '报考专业代码',
          dataIndex: 'bkzydm'
        },
        {
          title: '报考专业',
          dataIndex: 'bkzy'
        },
        {
          title: '研究方向',
          dataIndex: 'yjfx'
        },
        {
          title: '科目一',
          dataIndex: 'kmy'
        },
        {
          title: '科目二',
          dataIndex: 'kme'
        },
        {
          title: '科目三',
          dataIndex: 'kmsan'
        },
        {
          title: '科目四',
          dataIndex: 'kms'
        },
        {
          title: '总分',
          dataIndex: 'zf'
        },
        {
          title: '政策加分分数',
          dataIndex: 'zcjffs'
        },
        {
          title: '总数（加分后）',
          dataIndex: 'zs'
        },
        {
          title: '上线状态',
          dataIndex: 'sxzt'
        },
        {
          title: '破格状态',
          dataIndex: 'pgzt'
        },
        {
          title: '操作',
          dataIndex: 'cz',
          fixed: 'right',
          width: 120,
          scopedSlots: { customRender: 'action' }
        }
      ],
      // custom table alert & rowSelection
      options: {
        alert: { show: false },
        rowSelection: {
          onChange: (selectedRowKeys, selectedRows) => {
            console.log(`selectedRowKeys: ${selectedRowKeys}`, 'selectedRows: ', selectedRows)
          },
          onSelect: (record, selected, selectedRows) => {
            console.log(record, selected, selectedRows)
          },
          onSelectAll: (selected, selectedRows, changeRows) => {
            console.log(selected, selectedRows, changeRows)
          }
        }
      },
      selectMenu: {
        yx: [] // 院系
      }
    }
  },
  computed: {
    ...mapState({
      systemInfo: state => state.app.systemInfo,
      TYPE0126: state => state.app['TYPE0126'] // 年级
    })
  },
  created () {
    this.initSelectMenu()
    this.loadData()
    selectArr.forEach(v => {
      this.$store.dispatch('app/setDictionary', v)
    })
  },
  methods: {
    initSelectMenu () {
      let allRequest = [
        this.$api.base.collegeAll()
      ]
      Promise.all(allRequest).then(res => {
        this.selectMenu = {
          yx: res[0].data
        }
      })
    },
    // 选择院系
    yxChange (code) {
      this.$set(this.queryParam, 'sszym', '')
      this.$api.base.majorAll({lsdwh: code}).then(res => {
        this.$set(this.selectMenu, 'zy', res.data)
      })
    },
    // 加载数据
    loadData () {
      return new Promise(resolve => { resolve() }).then(res => {
        this.data = [{
          xmbh: 'A001',
          xm: '章鱼',
          bkyx: '电子院',
          bkzydm: 'what',
          bkzy: '计算机',
          yjfx: 'AI',
          kmy: '100',
          kme: '80',
          kmsan: '80',
          kms: '99',
          zf: '300',
          zcjffs: '5',
          zs: '305',
          pgzt: '破处了',
          sxzt: '上线',
          key: 1
        }, {
          xmbh: 'A001',
          xm: '章鱼',
          bkyx: '电子院',
          bkzydm: 'what',
          bkzy: '计算机',
          yjfx: 'AI',
          kmy: '100',
          kme: '80',
          kmsan: '80',
          kms: '99',
          zf: '300',
          zcjffs: '5',
          zs: '305',
          pgzt: '破处了',
          sxzt: '上线',
          key: 12
        }, {
          xmbh: 'A001',
          xm: '章鱼',
          bkyx: '电子院',
          bkzydm: 'what',
          bkzy: '计算机',
          yjfx: 'AI',
          kmy: '100',
          kme: '80',
          kmsan: '80',
          kms: '99',
          zf: '300',
          zcjffs: '5',
          zs: '305',
          pgzt: '破处了',
          sxzt: '上线',
          key: 18
        }]
      })
    },
    // 选择招生年度
    zsndChange () {

    },
    // 导出
    handleExport () {
      console.log('导出')
    },
    // 批量申请
    handleBatchApply () {
      this.bonusApplyVisible = true
    },
    // 取消录取
    handleApplyClose (data) {
      this.bonusApplyVisible = false
    },
    // 提交
    handleApplySuccess () {
      this.bonusApplyVisible = false
    }
  }
}
</script>

<style lang="less" scoped>
.card{
  margin-bottom: 20px;
}
</style>
